package com.wkn.wknAdmin.result;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * @Title:
 * @Description:
 * @Author: WKN
 * CreateDate: 2022/7/25 11:34
 */

@Getter
@Setter
@NoArgsConstructor
public class ResultVO<T> {

    /**
     * 状态码，比如1000代表响应成功
     */
    private int code;
    /**
     * 响应信息，用来说明响应情况
     */
    private String msg;
    /**
     * 响应的具体数据
     */
    private T data;

    public ResultVO(T data) {
        this(ResultCode.SUCCESS, data);
    }

    public ResultVO(ResultCode resultCode, T data) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = data;
    }

    /**
     * SUCCESS(1000, "操作成功")
     */
    public ResultVO Success(T data) {
        return new ResultVO(ResultCode.SUCCESS,data);
    }

    /**
     * Fail(1001, "操作失败")
     */
    public ResultVO Fail(T data) {
        return new ResultVO(ResultCode.FAILED,data);
    }

    public ResultVO Result(ResultCode resultCode,T data) {
        return new ResultVO(resultCode,data);
    }
}
